﻿using Microsoft.Practices.Prism.ViewModel;

namespace Warehouse.Silverlight.Core.Infrastructure.Models
{
    public abstract class Model : NotificationObject
    {
        // Must override
        protected abstract void Initialize();

        // Overridable
        protected virtual void Cleanup()
        {
        }

        #region IsBusy

        private int _busyCounter;
        protected int BusyCounter
        {
            get { return _busyCounter; }
            set
            {
                if (_busyCounter != value)
                {
                    _busyCounter = value;
                    RaisePropertyChanged(() => IsBusy);
                }
            }
        }
        public bool IsBusy
        {
            get; //{ return BusyCounter > 0; }
            protected set; //{ }
        }

        #endregion

        #region HasChanges

        private int _changesCounter;
        protected int ChangesCounter
        {
            get { return _changesCounter; }
            set
            {
                if (_changesCounter != value)
                {
                    _changesCounter = value;
                    RaisePropertyChanged(() => HasChanges);
                }
            }
        }
        public bool HasChanges
        {
            get; //{ return ChangesCounter > 0; }
            protected set; //{ }
        }

        #endregion

        #region HasErrors

        private int _errorsCounter;
        protected int ErrorsCounter
        {
            get { return _errorsCounter; }
            set
            {
                if (_errorsCounter != value)
                {
                    _errorsCounter = value;
                    RaisePropertyChanged(() => HasErrors);
                }
            }
        }
        public bool HasErrors
        {
            get { return ErrorsCounter > 0; }
        }

        #endregion
    }
}
